import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './router'
import { isLogin, activeTitle } from './customzie/util'
Vue.use(VueRouter)

const router = new VueRouter({
  routes,
})
/**
 * @解决Router重复点击相同路由出现报错
 */
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch((err) => err)
}

/**
 * @全局前置守卫
 */
router.beforeEach((to, from, next) => {
  isLogin(this, to, next)
  activeTitle(to, next)
})

export default router
